#include "EntityBackground.h"

CEntityBackground::CEntityBackground(int startPositionBackgroundX, int startPositionBackgroundY, 
									 int indexSprite1, int indexSprite2, int speed, bool active):
					startPositionBackgroundX(startPositionBackgroundX),
					startPositionBackgroundY(startPositionBackgroundY),
					indexMap2(indexSprite2), positionXMap2(0), positionYMap2(-1160)
{
	assert(indexSprite1>=0);
	assert(indexSprite2>=0);

	this->indexSprite=indexSprite1;

	this->currentPosX=startPositionBackgroundX;
	this->currentPosY=startPositionBackgroundY;

	this->speed=speed;
	this->collisionCost=0;
	this->active=active;
	this->side=eSideNeutral;

	//we don't use those two variables
	this->previousPosX=0;
	this->previousPosY=0;
}

CEntityBackground::~CEntityBackground(void){}

void CEntityBackground::update()
{
	currentPosY+=speed;
	positionYMap2+=speed;
	//if the top of the map is at the top of the screen we need to display the other texture
	if(currentPosY>=-speed && currentPosY<=speed)
	{
		positionYMap2=-616;
	}
	//if the top of the map is at the top of the screen we need to display the other texture
	if(positionYMap2>=-speed && positionYMap2<=speed)
	{
		currentPosY=-1014;
	}
}

void CEntityBackground::render(void)
{
	VIS.displayFrame(indexMap2, positionXMap2, positionYMap2, 1, false);
	VIS.displaySprite( currentPosX, currentPosY, this->indexSprite,false);
}

int CEntityBackground::getStartPositionBackgroundX(void) const
{
	return this->startPositionBackgroundX;
}
int CEntityBackground::getStartPositionBackgroundY(void) const
{
	return this->startPositionBackgroundY;
}

void CEntityBackground::setStartPositionBackgroundX(int startPositionBackgroundX)
{
	this->startPositionBackgroundX=startPositionBackgroundX;
}
void CEntityBackground::setStartPositionBackgroundY(int startPositionBackgroundY)
{
	this->startPositionBackgroundY=startPositionBackgroundY;
}